#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
        int m = isWater.size(), n = isWater[0].size();
        vector<vector<int>> ret(m, vector<int>(n, -1));
        queue<pair<int, int>> q;
        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++)
                if (isWater[i][j])
                    ret[i][j] = 0, q.push({ i, j });
        while (q.size())
        {
            auto [r, c] = q.front(); q.pop();
            static int dx[4] = { 1,-1,0,0 };
            static int dy[4] = { 0,0,1,-1 };
            for (int i = 0; i < 4; i++)
            {
                int x = r + dx[i];
                int y = c + dy[i];
                if (x >= 0 && x < m && y >= 0 && y < n && ret[x][y] == -1)
                {
                    ret[x][y] = ret[r][c] + 1;
                    q.push({ x, y });
                }
            }
        }
        return ret;
    }
};